<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Floor planning</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/cvxbook/Ch08_geometric_probs/html/floor_plan.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Floor planning</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Section 8.8.1/2, Example 8.7, Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Original by Lieven Vandenberghe</span>
<span class="comment">% Adapted for CVX by Joelle Skaf - 11/13/05</span>
<span class="comment">% (a figure is generated)</span>
<span class="comment">%</span>
<span class="comment">% Rectangles aligned with the axies need to be place in the smallest</span>
<span class="comment">% possible bounding box. No overlap is allowed. Each rectangle to be placed</span>
<span class="comment">% can be reconfigured, within some limits. We are given relative</span>
<span class="comment">% positioning contrainsts on those rectangles, and minimal required areas.</span>
<span class="comment">% In the current problem, 5 rectangles are given</span>

<span class="comment">% input data</span>
n = 5;
Amin = [100 100 100 100 100; <span class="keyword">...</span>
         20  50  80 150 200; <span class="keyword">...</span>
        180  80  80  80  80; <span class="keyword">...</span>
         20 150  20 200 110];
r = 1;          <span class="comment">% minimum spacing constraints</span>

<span class="keyword">for</span> iter = 1:4
    A = Amin(iter,:);
    cvx_begin <span class="string">quiet</span>
        variables <span class="string">x(n)</span> <span class="string">y(n)</span> <span class="string">w(n)</span> <span class="string">h(n)</span> <span class="string">W</span> <span class="string">H</span>
        minimize ( W + H )
        x &gt;= r;
        y &gt;= r;
        w &gt;= 0;
        h &gt;= 0;
        x(5) + w(5) + r &lt;= W;    <span class="comment">% No rectangles at the right of Rectangle 5</span>
        x(1) + w(1) + r &lt;= x(3); <span class="comment">% Rectangle 1 is at the left of Rectangle 3</span>
        x(2) + w(2) + r &lt;= x(3); <span class="comment">% Rectangle 2 is at the left of Rectangle 3</span>
        x(3) + w(3) + r &lt;= x(5); <span class="comment">% Rectangle 3 is at the left of Rectangle 5</span>
        x(4) + w(4) + r &lt;= x(5); <span class="comment">% Rectangle 4 is at the left of Rectangle 5</span>
        y(4) + h(4) + r &lt;= H;    <span class="comment">% No rectangles on top of Rectangle 4</span>
        y(5) + h(5) + r &lt;= H;    <span class="comment">% No rectangles on top of Rectangle 5</span>
        y(2) + h(2) + r &lt;= y(1); <span class="comment">% Rectangle 2 is below Rectangle 1</span>
        y(1) + h(1) + r &lt;= y(4); <span class="comment">% Rectangle 1 is below Rectangle 4</span>
        y(3) + h(3) + r &lt;= y(4); <span class="comment">% Rectangle 3 is below Rectangle 4</span>
        w &lt;= 5*h;                <span class="comment">% Aspect ratio constraints</span>
        h &lt;= 5*w;
        w' &gt;= quad_over_lin([A.^.5;zeros(1,n)],h');
    cvx_end
    <span class="comment">% Plotting</span>
    subplot(2,2,iter)
    <span class="keyword">for</span> i=1:n
        fill([x(i); x(i)+w(i); x(i)+w(i); x(i)],[y(i);y(i);y(i)+h(i);y(i)+h(i)],0.90*[1 1 1]);
        hold <span class="string">on</span>;
        text(x(i)+w(i)/2, y(i)+h(i)/2,[<span class="string">'B'</span>,int2str(i)]);
    <span class="keyword">end</span>
    axis([0 W 0 H]);
    axis <span class="string">equal</span>; axis <span class="string">off</span>;
<span class="keyword">end</span>

<span class="comment">% print -deps floorplan-opt.eps</span>
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="floor_plan__01.png" alt=""> 
</div>
</div>
</body>
</html>